package com.lw.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.lw.common.aop.LogOperation;
import com.lw.common.enums.LogModuleEnum;
import com.lw.common.utils.ResultVo;
import com.mybatisflex.core.paginate.Page;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import com.lw.entity.TbDict;
import com.lw.service.TbDictService;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import java.util.List;

/**
 * 字典表 控制层。
 *
 * @author lw
 * @since 2025年05月17日 07:58:04
 */
@RestController
@Tag(name = "字典表接口")
@RequestMapping("/tbDict")
public class TbDictController {

    @Autowired
    private TbDictService tbDictService;

    /**
     * 添加字典表。
     *
     * @param tbDict 字典表
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @PostMapping("saveDict")
    @Operation(description="保存字典表")
    @SaCheckPermission("sys:dict:add")
    @LogOperation(module = LogModuleEnum.LOG_DICT, value = "添加字典表", params = false,result = false)
    public ResultVo<Boolean> saveDict(@RequestBody @Parameter(description="字典表")TbDict tbDict) {
        return ResultVo.success(tbDictService.saveDict(tbDict));
    }

    /**
     * 根据主键删除字典表。
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @DeleteMapping("deleteDict/{id}")
    @Operation(description="根据主键删除字典表")
    @SaCheckPermission("sys:dict:delete")
    @LogOperation(module = LogModuleEnum.LOG_DICT, value = "根据主键删除字典表", params = false,result = false)
    public ResultVo<Boolean> deleteDict(@PathVariable("id") @Parameter(description="字典表主键")Long id) {
        return ResultVo.success(tbDictService.deleteDict(id));
    }

    /**
     * 根据主键更新字典表。
     *
     * @param tbDict 字典表
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @PutMapping("updateDict")
    @Operation(description="根据主键更新字典表")
    @SaCheckPermission("sys:dict:edit")
    @LogOperation(module = LogModuleEnum.LOG_DICT, value = "根据主键更新字典表", params = false,result = false)
    public ResultVo<Boolean> update(@RequestBody @Parameter(description="字典表主键")TbDict tbDict) {
        return ResultVo.success(tbDictService.updateDict(tbDict));
    }

    /**
     * 查询所有字典表。
     *
     * @return 所有数据
     */
    @GetMapping("list")
    @Operation(description="查询所有字典表")
    public ResultVo<List<TbDict>> list() {
        return ResultVo.success(tbDictService.list());
    }

    /**
     * 根据字典表主键获取详细信息。
     *
     * @param id 字典表主键
     * @return 字典表详情
     */
    @GetMapping("getInfo/{id}")
    @Operation(description="根据主键获取字典表")
    public ResultVo<TbDict> getInfo(@PathVariable("id") Long id) {
        return ResultVo.success(tbDictService.getById(id));
    }

    /**
     * 分页查询字典表。
     * @return 分页对象
     */
    @GetMapping("getDictPage")
    @Operation(description="分页查询字典表")
    public ResultVo<Page<TbDict>> getDictPage(TbDict dict) {
        return ResultVo.success(tbDictService.getDictPage(dict));
    }

}
